cmake_minimum_required(VERSION 3.15)
project(QuoteServer VERSION 0.0.1 LANGUAGES CXX)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置默认构建类型
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif()

# 编译选项
if(MSVC)
    add_compile_options(/W4)
    if(CMAKE_BUILD_TYPE STREQUAL "Debug")
        add_compile_options(/Od /Zi)
    else()
        add_compile_options(/O2)
    endif()
else()
    add_compile_options(-Wall -Wextra -pedantic)
    if(CMAKE_BUILD_TYPE STREQUAL "Debug")
        add_compile_options(-g -O0)
    else()
        add_compile_options(-O3 -DNDEBUG)
    endif()
endif()

# 查找依赖包
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)

# 包含目录
include_directories(include)

# 源文件
set(SOURCES
    src/main.cpp
    src/quote_server.cpp
    src/quote_manager.cpp
    src/websocket_server.cpp
    src/market_data_simulator.cpp
    src/json_utils.cpp
    src/config_manager.cpp
    src/logger.cpp
)

# 头文件
set(HEADERS
    include/quote_server.h
    include/quote_manager.h
    include/websocket_server.h
    include/market_data_simulator.h
    include/json_utils.h
    include/quote_data.h
    include/config_manager.h
    include/logger.h
)

# 创建可执行文件
add_executable(quote_server ${SOURCES} ${HEADERS})

# 链接库
target_link_libraries(quote_server 
    Threads::Threads
    OpenSSL::SSL
    OpenSSL::Crypto
)

# Windows特定设置
if(WIN32)
    target_link_libraries(quote_server ws2_32 wsock32)
endif()

# 创建必要的目录
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/logs)

# 安装规则
install(TARGETS quote_server DESTINATION bin)
install(DIRECTORY config/ DESTINATION config)
install(DIRECTORY DESTINATION logs) 